package com.baizhi.controller;


import com.baizhi.entity.Sale;
import com.baizhi.service.SaleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengg
 * @since 2021-02-07
 */
@RestController
public class SaleController {
    @Autowired
    private SaleService ss;
    @PostMapping("sales")
    public Map<String,Object> insert(@RequestBody Sale sale){
        sale.setUserid(1);
        //sale.setSaledate(LocalDate.now());
        System.out.println(sale);
        ss.save(sale);
        return new HashMap(){{
            put("state",0);
            put("msg","添加成功");
        }};
    }
    @GetMapping("sales")
    public PageInfo<Sale> selectByPage(@RequestParam(defaultValue = "1")int pageNo,int pageSize,String orderBy){
        return ss.selectByPage(pageNo,pageSize,orderBy);
    }
}
